package cn.detu._05mvcboot02.common.response;


import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class JsonResult {
    private Integer state;
    private String message;
    private Object data;

//    1.针对没有具体数据返回
    public JsonResult(StateCode stateCode){
        this.state = stateCode.getState();
        this.message = stateCode.getMessage();
    }

//    2.针对有具体返回参数的
    public JsonResult(StateCode stateCode,Object data){
        this.state = stateCode.getState();
        this.message = stateCode.getMessage();
        this.data = data;
    }

//    3.针对于有具体数据返回的静态方法
    public static  JsonResult ok(Object data){
        return new JsonResult(StateCode.OPERATION_SUCCESS,data);
    }

//    4.针对于没有具体返回的静态
    public static JsonResult ok(){
        return ok(null);
    }


}
